package trip;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.UniqueConstraint;
import javax.persistence.Id;

@Entity
@Table(name = "ROUTE_STOPS",
		uniqueConstraints = @UniqueConstraint(columnNames={"route_id", "stop_number"}))
public class Route_stops {
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;
	
	@Column(name = "stop_number", nullable = false)
	private Integer stop_number;

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "route_id") 
	private Route route;

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "stop_id")
	private Stop stop;
	
	//constructors
	public Route_stops() {};
	
	public Route_stops(long id, Integer stop_number, Route route, Stop stop) {
		this.id = id;
		this.stop_number = stop_number;
		this.route = route;
		this.stop = stop;
	}
	
	//id
	public long getId() {
		return id;
	}

	public Route_stops setId(long id) {
		this.id = id;
		return this;
	}
	
	//stop_number
	public Integer getStopNumber() {
		return stop_number;
	}

	public Route_stops setStopNumber(Integer stop_number) {
		this.stop_number = stop_number;
		return this;
	}

	//route
	public Route getRoute() {
		return route;
	}
	
	public Route_stops setRoute(Route route) {
		this.route = route;
		return this;
	}

	//stop
	public Stop getStop() {
		return stop;
	}
	
	public Route_stops setStop(Stop stop) {
		this.stop = stop;
		return this;
	}
	
	public boolean equals(Route_stops rs) {
		if (rs == null)
			return false;
		if (this.id == rs.id && 
			this.stop_number == rs.stop_number &&
			this.route.equals(rs.route) &&
			this.stop.equals(rs.stop))
			return true;
		else
			return false;
	}
}